<?php

namespace App\Models\Ad;

use Illuminate\Database\Eloquent\Model;

class AdvertNode extends Model
{
   protected $fillable = ['name', 'image', 'description', 'sort_order', 'is_show'];

   protected $table = 'advert_nodes';

   //分类下有很多广告
   public function adverts()
   {
      return $this->hasMany(Advert::class, 'category_id');
   }

   //判断分类下是否有广告
   static function check_adverts($id)
   {
      $advert_node = self::with('adverts')->find($id);
      if ($advert_node->adverts->isEmpty()) {
         return true;
      }
      return false;
   }

}
